(function(window, angular, undefined){

	var module = angular.module('water.entity.sitePollutants',['waterCommon']);
	
	module.service('$sitePollutantsService',function($waterDataCommon){
		
		/**
		 * 查询污染物列表
		 * WWTP_ID
		 *  STATION_ID
		 * 
		 */
		this.getList = function(data){
			var promise = $waterDataCommon.post("/SitePollutants/getList",data);
			return promise;
		}
		/**
		 * 获取model
		 */
		this.getModel = function(key){
			var promise = $waterDataCommon.getModel("BC_SITE_POLL",key);
			return promise;
		}
		/**
		 * 删除model
		 */
		this.deleteModel = function(key){
			var promise = $waterDataCommon.deleteModel("BC_SITE_POLL",{key:key});
			return promise;
		}
		/**
		 * 更新
		 */
		this.updateModel = function(data){
			for(var i=0;i<data.BC_POLL_THRESHOLD_LIST.length;i++){
				if(data.BC_POLL_THRESHOLD_LIST[i].isNew){
					data.BC_POLL_THRESHOLD_LIST.remove(data.BC_POLL_THRESHOLD_LIST[i],"GUID");
				}
			}
			var promise = $waterDataCommon.updateModelWithChild("BC_SITE_POLL",data);
			return promise;
		}
		/**
		 * 更新，不更新子表
		 */
		this.updateModelWithOutChild = function(data){
			for(var i=0;i<data.BC_POLL_THRESHOLD_LIST.length;i++){
				if(data.BC_POLL_THRESHOLD_LIST[i].isNew){
					data.BC_POLL_THRESHOLD_LIST.remove(data.BC_POLL_THRESHOLD_LIST[i],"GUID");
				}
			}
			var promise = $waterDataCommon.updateModel("BC_SITE_POLL",data);
			return promise;
		}
		/**
		 * 获取阈值model
		 */
		this.getThresholdModel = function(key){
			var promise = $waterDataCommon.getModel("BC_POLL_THRESHOLD",key);
			return promise;
		}
		/**
		 * 增加阈值
		 */
		this.createThreshold = function(sitePollId,mn,threshold){
			threshold.SITE_POLLUTANTS_ID = sitePollId;
			threshold.MN = mn;
			var promise = $waterDataCommon.createModel("BC_POLL_THRESHOLD",threshold);
			return promise;
		}
		
		/**
		 * 编辑阈值
		 */
		this.updateThreshold = function(threshold){
			var promise = $waterDataCommon.updateModel("BC_POLL_THRESHOLD",threshold);
			return promise;
		}
		/**
		 * 删除阈值
		 */
		this.deleteThreshold = function(key){
			var promise = $waterDataCommon.deleteModel("BC_POLL_THRESHOLD",{key:key});
			return promise;
		}
		/**
		 * 编辑阈值,级联更新阈值用户信息
		 */
		this.updateThresholdWithChild = function(threshold){
			var promise = $waterDataCommon.updateModelWithChild("BC_POLL_THRESHOLD",threshold);
			return promise;
		}
		/**
		 * 设置标准阈值
		 */
		this.setStandardThreshold = function(thresholdid){
			var promise = $waterDataCommon.post("/SitePollutants/setStandardThreshold",{ThresholdGUID:thresholdid});
			return promise;
		}
		/**
		 * 获取站点污染物单位等数据
		 * STATION_ID
		 */
		this.getSitePollutantsParam = function(data){
			var promise =  $waterDataCommon.post("/SitePollutants/getSitePollutantsParam",data);
			return promise;
		}
		/**
		 * 获取站点污染物集合
		 */
		this.getSitePollutantsParams = function(data){
			var promise =  $waterDataCommon.post("/SitePollutants/getSitePollutantsParams",data);
			return promise;
		}
		
		/**
		 * 增加报警阈值周期
		 */
		this.createThresholdAlarmCycle = function(threshold_guid,thresholdCycleData){
			thresholdCycleData.ALARM_THREHOLD_GUID = threshold_guid;
			var promise = $waterDataCommon.createModel("POLL_ALARM_THRESHOLD_CYCLE_SET",thresholdCycleData);
			return promise;
		}
		/**
		 * 编辑报警阈值周期(不包括用户角色子表)
		 */
		this.updateThresholdAlarmCycle = function(cycleData){
			var promise = $waterDataCommon.updateModel("POLL_ALARM_THRESHOLD_CYCLE_SET",cycleData);
			return promise;
		}
		/**
		 * 编辑报警阈值周期(包括用户角色子表)
		 */
		this.updateThresholdAlarmCycleWithChild = function(cycleData){
			var promise = $waterDataCommon.updateModelWithChild("POLL_ALARM_THRESHOLD_CYCLE_SET",cycleData);
			return promise;
		}
		/**
		 * 获取报警阈值周期model
		 */
		this.getThresholdAlarmCycleModel = function(key){
			var promise = $waterDataCommon.getModel("POLL_ALARM_THRESHOLD_CYCLE_SET",key);
			return promise;
		}
	})
}(window, angular));